//
//  CPSCVideoLectureViewController.m
//  CPSCustomer
//
//  Created by hl on 2021/8/30.
//  Copyright © 2021 dgg_hzk. All rights reserved.
//

#import "CPSCVideoLectureViewController.h"
#import "CPSCVideoFilterListCategoryView.h"
#import "CPSCVideoLectureCollectionViewCell.h"

@interface CPSCVideoLectureViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (strong, nonatomic) UICollectionView * collectionView;

@property (nonatomic, strong) UIView * viewCategorySuper;
@property (nonatomic, strong) CPSCVideoFilterListCategoryView * viewCategoryContent;

@end

@implementation CPSCVideoLectureViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setUpMainUI];
}

- (void)setUpMainUI
{
    [self.view addSubview:self.collectionView];
    [self.view addSubview:self.viewCategorySuper];
    [self.viewCategorySuper addSubview:self.viewCategoryContent];
    
    [self makeContraints];
    
    [self debugUI];
}


- (void)makeContraints {
    
    [self.viewCategorySuper mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(48);
        make.top.left.right.mas_equalTo(0);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.viewCategorySuper.mas_bottom);
        make.bottom.left.right.mas_equalTo(0);
        
    }];
    
    [self.viewCategoryContent mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.left.right.mas_equalTo(0);
    }];
    
    
}

- (void)debugUI
{
//    self.view.backgroundColor = [UIColor redColor];
//    self.collectionView.backgroundColor = UIColor.yellowColor;
    
//    self.viewCategorySuper.backgroundColor = UIColor.yellowColor;
    
}

#pragma mark - UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    CPSCVideoLectureCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([CPSCVideoLectureCollectionViewCell class]) forIndexPath:indexPath];
    
//    cell.backgroundColor = kCPSCRandomColor;
    return cell;
}

#pragma mark--UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
//    [self scrollWithScrollView:scrollView];
}


#pragma mark - Getter Setter

- (UICollectionView *)collectionView {
    if (!_collectionView) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        
        CGFloat margin = 5;
        CGFloat column = 2;
        CGFloat sectionInsetLR = margin * 2;
        CGFloat rowAllMargin = margin * (column -1);
        CGFloat cellWidth = (ScreenWidth - rowAllMargin - sectionInsetLR) / column;
        
        
        CGFloat cellHeight = 200;
        flowLayout.itemSize = CGSizeMake(cellWidth, cellHeight);
        flowLayout.minimumInteritemSpacing = margin;
        flowLayout.minimumLineSpacing = margin;
//        UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
        flowLayout.sectionInset = UIEdgeInsetsMake(margin, margin, 0, margin);
        
                        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        [_collectionView registerClass:[CPSCVideoLectureCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([CPSCVideoLectureCollectionViewCell class])];
    }
    
    return _collectionView;
}



- (UIView *)viewCategorySuper
{
    
    if (!_viewCategorySuper) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        
        _viewCategorySuper = view;
    }
    return _viewCategorySuper;
}

- (CPSCVideoFilterListCategoryView *)viewCategoryContent
{
    DggWEAKSELF(weakSelf);
    if (!_viewCategoryContent) {
        
        CPSCVideoFilterListCategoryView * view = [[CPSCVideoFilterListCategoryView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        
        view.blockEdit = ^{
            
        };
        
        view.blockSelect = ^(id  _Nonnull item) {
            
        };
        
        _viewCategoryContent = view;
    }
    return _viewCategoryContent;
}


#pragma mark - request
@end
